package com.sa.commons.dao.hiber.inter;

import org.hibernate.Session;

import com.sa.commons.exception.DBDataErrorException;
import com.sa.commons.exception.DBErrorException;

/**
 * 
 * @author 黄欣
 * 
 * @param <E>
 * @param <PK>
 */
public interface GenericDao<PK,E>{


	/**
	 * 根据实体id获得
	 * 
	 * @param id
	 * @return
	 * @throws DBDataErrorException 
	 */
	E getForUpdate(PK id) throws DBErrorException,DBDataErrorException;

	/**
	 * 根据实体Id获得
	 * 
	 * @param id
	 * @return
	 * @throws DBDataErrorException 
	 */
	E get(PK id)throws DBErrorException,DBDataErrorException;

	/**
	 * 保存对象
	 * 
	 * @param entity
	 * @throws DBDataErrorException 
	 */

	E save(E entity)throws DBErrorException,DBDataErrorException;

	
	/**
	 * 更新或者保存
	 * 
	 * @param entity
	 * @throws DBDataErrorException 
	 */

	E saveOrUpdate(E entity) throws DBErrorException,DBDataErrorException;
	/**
	 * 根据ID删除相关信息
	 * 
	 * @param id
	 * @throws DBDataErrorException 
	 */
	void delete(PK id) throws DBErrorException,DBDataErrorException;


	/**
	 * 更新实体对象对应的信息
	 * 
	 * @param entity
	 * @throws DBDataErrorException 
	 */
	E update(E entity) throws DBErrorException,DBDataErrorException;
	
	/**
	 * 
	 */
	Session getSession();

}
